<template>
  <div v-loading="loading">
    <div class="search-box">
      <div class="search-form">
        <el-form ref="searchForm" :inline="true" :model="searchForm">
          <el-form-item label="业务名称" prop="procDefKey">
            <el-select v-model="searchForm.procDefKey" clearable style="width:180px;">
              <el-option
                v-for="item in procDefKeyOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="onSearch">查询</el-button>
            <el-button icon="el-icon-remove-outline" title="重置" @click="resetSearchForm" />
          </el-form-item>
        </el-form>
      </div>
    </div>

    <el-table
      ref="multipleTable"
      stripe
      :data="tableData"
      border
      class="table"
    >
      <el-table-column prop="procDefKey" label="业务名称">
        <template slot-scope="scope">
          {{ scope.row.procDefKey|toProcessName }}
        </template>
      </el-table-column>
      <el-table-column prop="procName" label="申请标题" />
      <el-table-column prop="applicant" label="申请人" />
      <el-table-column prop="applyTime" label="申请时间" width="170">
        <template slot-scope="scope">
          <span>{{ scope.row.applyTime | parseTime("{y}-{m}-{d} {h}:{i}") }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="任务名称" />
      <el-table-column prop="createTime" label="任务开始时间" width="170">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime | parseTime("{y}-{m}-{d} {h}:{i}") }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="endTime" label="任务结束时间" width="170">
        <template slot-scope="scope">
          <span>{{ scope.row.endTime | parseTime("{y}-{m}-{d} {h}:{i}") }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="taskComment" label="审批意见" />
      <el-table-column label="操作" width="90" align="left">
        <template slot-scope="scope">
          <el-button type="text" @click="handleShow(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" :page.sync="curPage" :limit.sync="limit" @pagination="getList" />
    <!--表单组件-->
    <awardShow ref="awardShow" />
    <trainingShow ref="trainingShow" />
    <socialJobShow ref="socialJobShow" />
    <publishShow ref="publishShow" />
    <leaveShow ref="leaveShow" />
  </div>
</template>

<script>
import request from '@/utils/request'
import Pagination from '@/components/Pagination'
import { processKeys } from '@/api/basedata'
import awardShow from '../../edu/award/list/show'
import trainingShow from '../../edu/training/list/show'
import socialJobShow from '../../edu/socialjob/list/show'
import publishShow from '../../edu/publish/list/show'
import leaveShow from '../../edu/leave/list/show'
export default {
  name: 'ProcessHistory',
  components: { Pagination, awardShow, trainingShow, socialJobShow, publishShow, leaveShow },
  data() {
    return {
      curPage: 1,
      limit: 5,
      total: 0,
      loading: true,
      downloadLoading: false,
      orderByClause: null,
      procDefKeyOptions: processKeys,
      tableData: [],
      searchForm: {
        procDefKey: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取数据
    getList() {
      this.loading = true
      const param = {}
      const queryPage = {}
      queryPage.limit = this.limit
      queryPage.offset = this.limit * (this.curPage - 1)
      param.page = queryPage
      if (this.orderByClause && this.orderByClause.trim() !== '') {
        param.orderByClause = this.orderByClause
      }
      this.copyNotBlankField(this.searchForm, param)
      request({ url: '/task/findHistoryTasks', method: 'post', data: param })
        .then(res => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
          this.curPage = res.pageNumber
        })
        .catch(e => {
          this.loading = false
          this.$message.error('查询出错')
        })
    },
    onSearch() {
      this.getList()
    },
    resetSearchForm() {
      this.$refs['searchForm'].resetFields()
    },
    handleShow(row) {
      if (row.procDefKey === 'award') {
        this.$refs.awardShow.show(row.businessKey)
      } else if (row.procDefKey === 'training') {
        this.$refs.trainingShow.show(row.businessKey)
      } else if (row.procDefKey === 'socialJob') {
        this.$refs.socialJobShow.show(row.businessKey)
      } else if (row.procDefKey === 'publish') {
        this.$refs.publishShow.show(row.businessKey)
      } else if (row.procDefKey === 'leave') {
        this.$refs.leaveShow.show(row.businessKey)
      }
    }

  }
}
</script>
